import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-18
 * Time: 22:49
 */
public class Main {
    //旋转数组,顺序表解法//时间复杂度不行
    public static void rotate1(int[] nums, int k) {
        int time = k % nums.length;
        for(int i = 0;i < time;i++){
            int temp = nums[nums.length - 1];
            for(int j = nums.length - 1;j > 0;j--){
                nums[j] = nums[j - 1];
            }
            nums[0] = temp;
        }
        System.out.println(Arrays.toString(nums));
    }
    //旋转数组
    public static void rotate2(int[] nums, int k) {
        int[] temp = nums.clone();
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            nums[ (i + k) % len ] = temp[i];
        }
        System.out.println(Arrays.toString(nums));
    }



    //面试题 17.04. 消失的数字//哈希的思想
    public static int missingNumber(int[] nums) {
        int[] temp = new int[nums.length + 1];
        int count = -1;
        for(int i = 0;i < nums.length;i++){
            temp[nums[i]] = nums[i];
            if(nums[i] == 0){
                count = 0;
            }
        }
        if(count == -1){
            for(int i = 0;i < temp.length;i++){
                if(temp[i] == 0){
                    return i;
                }
            }
        }
        if(count == 0){
            for(int i = 1;i < temp.length;i++){
                if(temp[i] == 0){
                    return i;
                }
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,6,7};
        int k = 3;
        rotate1(nums,140000000);
        rotate2(nums,140000000);
        System.out.println("缺少的数字是" + missingNumber(nums));
    }
}